<!-- 左侧，水资源 -->
<div class="navbar-header">
    <a class="navbar-brand" href="index.html"><i class="fa fa-gavel"></i> <strong>工业水资源管理</strong></a>
</div>
<ul class="nav navbar-top-links navbar-right">
    <!-- 右侧，用户 -->
<!--    <li class="dropdown">-->
<!--        <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">-->
<!--            <i class="fa fa-bell fa-fw"></i> <i class="fa fa-caret-down"></i>-->
<!--        </a>-->
<!--        <ul class="dropdown-menu dropdown-alerts">-->
<!--            <li>-->
<!--                <a href="#">-->
<!--                    <div>-->
<!--                        <i class="fa fa-comment fa-fw"></i> New Comment-->
<!--                        <span class="pull-right text-muted small">4 min</span>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </li>-->
<!--            <li class="divider"></li>-->
<!--            <li>-->
<!--                <a href="#">-->
<!--                    <div>-->
<!--                        <i class="fa fa-twitter fa-fw"></i> 3 New Followers-->
<!--                        <span class="pull-right text-muted small">12 min</span>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </li>-->
<!--            <li class="divider"></li>-->
<!--            <li>-->
<!--                <a href="#">-->
<!--                    <div>-->
<!--                        <i class="fa fa-envelope fa-fw"></i> Message Sent-->
<!--                        <span class="pull-right text-muted small">4 min</span>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </li>-->
<!--            <li class="divider"></li>-->
<!--            <li>-->
<!--                <a href="#">-->
<!--                    <div>-->
<!--                        <i class="fa fa-tasks fa-fw"></i> New Task-->
<!--                        <span class="pull-right text-muted small">4 min</span>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </li>-->
<!--            <li class="divider"></li>-->
<!--            <li>-->
<!--                <a href="#">-->
<!--                    <div>-->
<!--                        <i class="fa fa-upload fa-fw"></i> Server Rebooted-->
<!--                        <span class="pull-right text-muted small">4 min</span>-->
<!--                    </div>-->
<!--                </a>-->
<!--            </li>-->
<!--            <li class="divider"></li>-->
<!--            <li>-->
<!--                <a class="text-center" href="#">-->
<!--                    <strong>See All Alerts</strong>-->
<!--                    <i class="fa fa-angle-right"></i>-->
<!--                </a>-->
<!--            </li>-->
<!--        </ul>-->
<!--        &lt;!&ndash; /.dropdown-alerts &ndash;&gt;-->
<!--    </li>-->

    <li id = "user_mdule" class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
            <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
        </a>
        <ul class="dropdown-menu dropdown-user">
<!--            <li><a href="#"><i class="fa fa-user fa-fw"></i> 用户信息</a>-->
<!--            </li>-->
<!--            <li class="divider"></li>-->
            <li><a href="#" id = "btn_login_out"><i class="fa fa-sign-out fa-fw"></i> 注销</a>
                <!--button id = "btn_login_out" class fa fa-sign-out fa-fw= "fa fa-sign-out fa-fw">注销</button-->
            </li>
            <li><a href="#" id = "reset" ><i class="fa fa-sign-out fa-fw"></i> 修改密码</a>
                <!--button id = "btn_login_out" class = "fa fa-sign-out fa-fw">注销</button-->
            </li>
        </ul>
    </li>

</ul>

<div class="modal fade" id="reset_pwd" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">重置密码</h4>
            </div>
            <div class="form-group">
                <label>用户名</label>
                <input class="form-control" placeholder="请输入用户名"  id="reset_user_name" type="text" >
            </div>
            <div class="form-group">
                <label>新密码</label>
                <input class="form-control" placeholder="请输入新密码" id="new_pwd" type="password">
            </div>
            <div class="form-group">
                <label>确认密码</label>
                <input class="form-control" placeholder="请再次输入新密码" id="new_pwd_confirm" type="password">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="reset_pwd_submit">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script>
    $('#btn_login_out').click(function(){
        //console.log("点击了注销")
        $.ajax({
            type: 'get',
            url: '/user_control/login_out',
            async: false,
            success: function (data) {
                $('#user_mdule').hide();
                //console.log(data)
                window.alert("用户注销成功");
                window.location.reload();
            }
        });
    })
    var username="";
    $('#reset').click(function(){
        console.log("点击修改密码")
        $.ajax({
        type : "get",
        url : "/user_control/reset_and_logout",
        async : false,
        success : function(data){
            username=data.username;
            $.ajax({
                type : "post",
                url : "/user_control/isUser",
                data : {
                    username : username,
                },
                async : false,
                success : function(data){
                if (data.status == "success") {
                    //console.log(data);
                    old_pwd = data.rows.password;
                    email=data.rows.email;
                    if (email== "" || email == null){
                        window.alert('用户邮箱地址不存在！');
                        return;
                    };
                    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                    if (!myreg.test(email)){
                        window.alert('用户邮箱格式不正确！');
                        return;
                    };
                    window.alert('请登录到邮箱重置密码');
                    //sendMail(username,email);
                    $.ajax({
                        type : "post",
                        url : "/user_control/sendEmail",
                        data : {
                            username : username,
                            email:email
                        },
                        async : false,
                        success : function(data) {
                            console.log("send Email:"+data);
                        }
                    });

                } else {
                    window.alert(data.msg);
                    return;
                }
            }//success
            });//ajax
        }
    })
    })//click reset

</script>
